package cn.getech.data.development.controller.api;

import cn.getech.data.development.api.WorkFlowDepApi;
import cn.getech.data.development.constant.LastRunState;
import cn.getech.data.development.entity.JobInfo;
import cn.getech.data.development.entity.WorkFlowDep;
import cn.getech.data.development.service.WorkFlowDepService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Objects;

/**
 * @ClassName JobInfoApiController
 * @Description TODO
 * @Author Getech
 * @Date 2020/12/24 11:46
 */
@RestController
public class WorkFlowDepApiController implements WorkFlowDepApi {

    @Autowired
    private WorkFlowDepService workFlowDepService;

    @Override
    public WorkFlowDep getWorkFlowDepById(Long workFlowDepId) {
        return workFlowDepService.getById(workFlowDepId);
    }

    @Override
    public void updateWorkFlowDepById(WorkFlowDep workFlowDep) {
        workFlowDepService.updateById(workFlowDep);
    }

    @Override
    public List<WorkFlowDep> selectListByStatus(Integer status) {
        return workFlowDepService.list(new QueryWrapper<WorkFlowDep>().eq("last_run_state",status));
    }

    @Override
    public void updateWorkFlowDepAndStatusById(WorkFlowDep workFlowDep) {
        //先查询对应的任务数据（然后处理对应的停止状态）
        WorkFlowDep workFlowDep1 = workFlowDepService.getById(workFlowDep.getId());
        if(null != workFlowDep1 && Objects.equals(workFlowDep1.getLastRunState(), LastRunState.STOP.getCode())){
            workFlowDep.setLastRunState(LastRunState.STOP.getCode());
        }
        workFlowDepService.updateById(workFlowDep);
    }
}
